package dataservice.financialdataservice.driver;

import java.util.ArrayList;

import po.AccountPO;
import po.ClientPO;
import po.PayList;
import po.PayPO;
import po.PayPOLineItem;
import po.ReceiveList;
import po.ReceivePO;
import po.ReceivePOLineItem;
import po.UserPO;
import utility.TimePeriod;
import data.financialdata.stub.MoneyDataServiceSerializableImplStub;
import dataservice.financialdataservice.MoneyDataService;

public class MoneyDataService_Driver {
	
	public void drive(MoneyDataService moneyDataService){
		ClientPO client = new ClientPO();
		ArrayList<PayPOLineItem> lineItemList = new ArrayList<PayPOLineItem>();
		AccountPO account = new AccountPO("Nero",2133);
		lineItemList.add(new PayPOLineItem("accountId",21312,"comment"));
		UserPO user = new UserPO("User1","x007","325400");
		PayPO paypo = new PayPO("clientId",new PayList(),1321,"userId");
		boolean result = moneyDataService.addPay(paypo);
		if(result){
			System.out.println("add Pay pass");
		}else{
			System.out.println("add Pay failed");
		}
		
		ArrayList<ReceivePOLineItem> receiveLineItemList = new ArrayList<ReceivePOLineItem>();
		receiveLineItemList.add(new ReceivePOLineItem("accountId",21312,"comment"));
		ReceivePO receivepo = new ReceivePO("clientId",new ReceiveList(),1321,"userId");
		result = moneyDataService.addReceive(receivepo);
		
		if(result){
			System.out.println("add Receive pass");
		}else{
			System.out.println("add Receive failed");
		}
		
		PayPO pay = moneyDataService.findPay("FKD-yyyyMMdd-12321");
		if(pay != null){
			System.out.println("find pay pass");
		}else{
			System.out.println("find pay failed");
		}
		
		ReceivePO receive = moneyDataService.findReceive("SKD-yyyyMMdd-12345");
		if(receive != null){
			System.out.println("find receive pass");
		}else{
			System.out.println("find receive failed");
		}
		
		TimePeriod period = null;
		try {
			period = new TimePeriod("2014-2-3","2014-6-3");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ArrayList<PayPO> payList = moneyDataService.mutipleConditionFindPay(period, client, user);
		if(!payList.isEmpty()){
			System.out.println("mutiple condition find pay pass");
		}else{
			System.out.println("mutiple condition find pay failed");
		}
		
		ArrayList<ReceivePO> receiveList = moneyDataService.mutipleConditionFindReceive(period, client, user);
		if(!receiveList.isEmpty()){
			System.out.println("mutiple condition find receive pass");
		}else{
			System.out.println("mutiple condition find receive failed");
		}
		
		moneyDataService.init();
		moneyDataService.finish();
	}
	
	public static void main(String[] args) {
		MoneyDataService_Driver driver = new MoneyDataService_Driver();
		MoneyDataService moneyDataService = new MoneyDataServiceSerializableImplStub();
		driver.drive(moneyDataService);
	}
}
